package com.cslg.yougou.front.service.impl;

import com.cslg.yougou.front.entity.ShopCar;
import com.cslg.yougou.front.mapper.ShopCarMapper;
import com.cslg.yougou.front.pojo.Result;
import com.cslg.yougou.front.pojo.ShopCarPojo;
import com.cslg.yougou.front.service.ShopCarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zx
 * @since 2020-11-07
 */
@Service
public class ShopCarServiceImpl extends ServiceImpl<ShopCarMapper, ShopCar> implements ShopCarService {
    @Override

    public Result getshopcar (String token, String current_time){
        if (StringUtils.isEmpty(token) || StringUtils.isEmpty(current_time)) {
            return Result.errorMsg("token or current_time is empty");
        }
        List<ShopCarPojo> shopCarPojos = null;
        try {
            shopCarPojos = this.baseMapper.selectshopcarByMd5Id(token);
        }catch (Exception e){
            return Result.errorMsg("Database Error!");
        }
        return Result.ok(shopCarPojos);
    }

    public Result addshopcar( String token,String current_time,int shopcarid){
        try {
            this.baseMapper.addShopcarByMd5(shopcarid);
        }catch (Exception e){
            return Result.errorMsg("Add Error!");
        }
        return Result.ok();
    }
    public Result subshopcar( String token,String current_time,int shopcarid){
        try {
            this.baseMapper.subShopcarByMd5(shopcarid);
        }catch (Exception e){
            return Result.errorMsg("Sub Error!");
        }
        return Result.ok();
    }
}

